/**
 * Created by hkf6644 on 2017/5/27.
 */
var accessAddObj = {
    addParamObj : {
        sysName : '',
        url : '',
        ouId : '',
        sysId : ''
    },
    ouId : '',
    orgData : [],
    isSuper : true,
    addTitle : ''
};

var initAddAccessData = function (isEditor) {
    if (getRoleJuri() !== 'super_admin') {
        accessAddObj.isSuper = false;
    } else {
        accessAddObj.isSuper = true;
    }
	
    getOrgList(true);
};

Vue.component('createNewAccess', {
    props: [],
    template : CommonFunc.ajax.getOuterHtml('component/access_add.html'),
    data: function () {
        return accessAddObj
    },
    watch : {

    },
    methods: {
        saveUser : function () {
            var _this = this;

            if (_this.addParamObj.sysId) {
                var saveUrl = '/cas/console/sys/edit.ajax';
            } else {
                var saveUrl = '/cas/console/sys/add.ajax';
            }

            if (!_this.addParamObj.sysName) {
                vmdata.warningAlert = '请填写系统名称！';
                return false;
            }

            if (!_this.addParamObj.url) {
                vmdata.warningAlert = '请填写URL！';
                return false;
            }

            if (!_this.addParamObj.ouId) {
                vmdata.warningAlert = '请选择组织！';
                return false;
            }

            var saveCallback = function (rs) {
                if (rs.isSuccess) {
                    if (_this.addParamObj.userId) {
                        vmdata.successAlert = '编辑系统成功！';
                    } else {
                        vmdata.successAlert = '新建系统成功！';
                    }

                    getAccessList.call(_this, 1);

                    vmdata.modal.showAccess = false;
                } else {
                    vmdata.errorAlert = rs.errMsg;
                }
            };

            $.ajax({
                type: "POST",
                url: saveUrl,
                async: true,
                contentType: "application/json",
                dataType: "json",
                data: JSON.stringify(_this.addParamObj),
                success: saveCallback
            });
        },
        cancleUser : function () {
            vmdata.modal.showAccess = false;
        }
    }
});